mangafandomcom-20200224-history
Conditional comment
Conditional comments are conditional statements interpreted by Microsoft Internet Explorer in HTML source code. Conditional comments first appeared in Microsoft's Internet Explorer 5 browser and are supported through at least version 8. Conditional comments can be used to provide and hide code to and from Internet Explorer. There are two types of "conditional comments": downlevel revealed, and downlevel hidden. Examples Here is a simple example that demonstrates how conditional comments work. You are not using Internet Explorer. Syntax of Conditional Comments The basic syntax of each type of comment is shown in the following table. The first comment shown is the basic HTML Comment, which is included for the purpose of comparison and to illustrate the different syntax used by each type of conditional comment. The HTML shown inside the syntax block in each of the conditional comments denotes any block of HTML content, including script. Both types of conditional comment use a conditional expression to indicate whether the content inside the comment block should be parsed or ignored. The conditional expression is formed from a combination of feature, operator, and/or value, depending on the feature. The following table shows the supported features and describes the values each feature supports. The following table describes the operators that can be used to create conditional expressions. Downlevel-hidden conditional comment Below are two examples of a "downlevel hidden" conditional comment: or The directive in the first example will let IE 8 read the specified CSS file, while IE 7 or older IE versions will ignore it. Browsers other than IE will also ignore it because it looks like a standard HTML comment. The tag in the second example will let IE versions 5.0 through 7 read the internal CSS style. With different uses of this tag you can also single out IE 6, IE 5, or versions of IE that are newer (greater) or older (less) than a specified version. Downlevel-revealed conditional comment Below is an example of a "downlevel revealed" conditional 'comment', which is not an (X)HTML comment at all, despite the misleading name, using the default Microsoft syntax: This example shows content that should be exposed only to non-IE browsers, as the condition evaluates to "false" on IE (and hence the content is ignored), while the tags themselves are unrecognized (and hence ignored) on non-IE browsers. This is not valid HTML or XHTML. Microsoft acknowledges this syntax is not standardized markup, intending these tags to be overlooked by other browsers and expose the content in the middle. In order to ensure compliance with W3C standards, some web developers use an alternative techniqueValid downlevel-revealed conditional comments 456 Berea Street for downlevel-revealed conditional comments: While somewhat confusing in structure, this specific syntax is valid (X)HTML and is useful for conditional sections intended specifically for non-IE browsers; if the condition evaluates to true (for example, if writing code meant to display on non-IE browsers and on some versions of IE), IE will then display the "-->" present before the HTML content. This problem is easily solved by prepending "" as follows: The extra """ is unrecognized and therefore ignored. While this method is functional in current versions of Internet Explorer, there is no guarantee that future versions will continue to operate this way. Conditional Comment in JScript Starting with Internet Explorer 4, there exists a similar proprietary mechanism for adding conditional comments within JScript, known as Conditional Compilation. Code examples: There were also several predefined variables,Conditional Compilation Variables though these cannot be relied on any longer as Microsoft altered the JScript engineDetecting IE7+ in JavaScript of IE6 with XP SP3 and it now reports as: @_jscript_version 5.7 As a result, the way to detect IE 6 using conditional compilation can be seen below: See also *CSS filter References Category:HTML Category:Cascading Style Sheets Category:Internet Explorer de:Conditional Comments es:Comentarios condicionales ru:Условный комментарий